package work.demo;

import work.LogReader;
import work.config.Constant;
import work.fram.*;
import work.utils.CommonExcelUtils;

import java.io.File;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommunistParty {

    public static void main(String[] args) throws SQLException {

        AutoLogger logger = AutoLogger.getINTERFACE();

        //读取Excel文件
        List<Map<String, String>> list = CommonExcelUtils.e2m(new File(Constant.work, "2019年党员信息 - 副本(1).xls"), "sheet0", 1);

        Map<String, String> idcard_orgName = new HashMap<>();

        for (Map<String, String> map : list) {

            String s = map.get("身份证号码");

            idcard_orgName.put(s, map.get("姓名"));

        }


        LogReader reader = LogReader.create("在tc_md_personnel未找到该身份证号");

        if (reader != null) {


            String line;

            while ((line = reader.readLine()) != null) {

                logger.writeLine("在tc_md_personnel未找到该身份证号_带有姓名", line,idcard_orgName.get(line.trim()));

            }


            reader.close();
        } else {
            System.out.println("没有找到文件");
        }

        logger.close();


/*

        SqlMaker sqlMaker = new SqlMaker();
        KeyValueMapper keyValueMapper = new KeyValueMapper();
        sqlMaker.setKeyValueMapper(keyValueMapper);

        sqlMaker.setTable("sys_bus_org_person");

        keyValueMapper.putInvariable("create_time", "2019-11-25 00:01:02");


        Statement ins = JDBCConnect.getStatement();

        Statement q = JDBCConnect.getStatement();

        Statement userQ = JDBCConnect.getStatement();

        idcard_orgName.forEach((ic, orgName) -> {

            try {


                ResultSet resultSet = q.executeQuery("SELECT id,code,pid FROM bus_org WHERE name=\"" + orgName + "\"");

                if (resultSet.last()) {

                    if (resultSet.getRow() == 1) {
                        //查询到的code和id
                        String code = resultSet.getString("code");

                        if (code != null) {
                            //根据身份证号找到这个人
                            ResultSet query = userQ.executeQuery("select mdcode,sysid from tc_md_personnel where idcard=\"" + ic + "\"");
                            if (query.last()) {
                                if (query.getRow() != 1) {
                                writer.writeLine("在tc_md_personnel同一个身份证号找到多个记录", ic);
                                }
                            } else {
                                writer.writeLine("在tc_md_personnel未找到该身份证号", ic);
                            }

                        }
                    } else {
                        writer.writeLine("在bus_org中找到多个同名的组织机构", ic, orgName);
                    }


                } else {
                    writer.writeLine("没有在bus_org中找到相应的组织机构", ic, orgName);
                }
            } catch (Exception e) {
                e.printStackTrace();

            }

        });
        logger.close();
*/


    }


}
